

$(function () {



    //头部导航栏
    (function () {

        var $Nav = $("#topnav .right .nav li"),
            $About = $("#topnav .right .about"),
            $aboutLi = $About.children("li"),
            $Search = $("#topnav .right .more > span:nth-of-type(1)"),
            $Input = $("#topnav .right .more input"),
            $Email = $("#topnav .right .more .email"),
            $sEmail =$("#topnav .right .more > span:nth-of-type(2)"),
            $aboutUs = $("#main #us > div"),
            $span = $("#topnav .right .more > p span");

        var $Unav = $("#main #us .u-nav li");

        $Nav.click(function () {
            $(this).find("a").addClass("on").end().siblings().find("a").removeClass("on");
        });


        $Nav.eq(1).hover(
            function () {
                $About.eq(0).stop().slideDown(500);
            },
            function () {
                $About.eq(0).stop().slideUp(500);
            });

        $Nav.eq(2).hover(
            function () {
                $About.eq(1).stop().slideDown(500);
            },
            function () {
                $About.eq(1).stop().slideUp(500);
            });

        $Nav.eq(3).hover(
            function () {
                $About.eq(2).stop().slideDown(500);
            },
            function () {
                $About.eq(2).stop().slideUp(500);
            });

        $Nav.eq(4).hover(
            function () {
                $About.eq(3).stop().slideDown(500);
            },
            function () {
                $About.eq(3).stop().slideUp(500);
            });

        $Nav.eq(5).hover(
            function () {
                $About.eq(4).stop().slideDown(500);
            },
            function () {
                $About.eq(4).stop().slideUp(500);
            });

        $About.hover(
            function () {
                $(this).stop().slideDown(500);
            },
            function () {
                $(this).stop().slideUp(500);
            }
        );

        $Search.click(function () {
            if($Input.hasClass("d-n")){
                $Input.removeClass("d-n");
            }else{
                $('#search-btn').click();
                $Input.addClass("d-n");
            }

        });

        $sEmail.hover(
            function () {
                $Email.removeClass("d-n");
            },
            function () {
                $Email.addClass("d-n");
            });

        $span.click(function () {

            $(this).addClass("on").siblings().removeClass("on");

        });


        var $phoneBTn = $("#topnav .right .phonebtn"),
            $phoneNav =$("#topnav .right .nav");





        $(window).resize(Width);


        Width();

        function Width() {
            if ($(window).width() < 800) {

                $phoneBTn.click(function(){
                    $phoneNav.stop().slideToggle("slow");
                });
            }
        }



        //关于我们
        $Unav.click(change);

        $aboutLi.click(function () {
            $Nav.eq(1).addClass("on").siblings().removeClass("on");
            change.call(this);
            $Main.eq(1).removeClass("d-n");
            $Main.eq(0).addClass("d-n");
        });

        function change() {
            $Unav.eq($(this).index()).find("div h3").addClass("on").end().siblings().find("div h3").removeClass("on");
            $Unav.eq($(this).index()).find("div p").addClass("on").end().siblings().find("div p").removeClass("on");
            $aboutUs.eq($(this).index()).addClass("on").siblings().removeClass("on");
        }

    })();

    //头部轮播
    ;(function () {

        var $pic = $("#home .shuffling .pic > li"),
            $more = $pic.find("div"),
            length=$pic.length,
            i=0;

        f2();

        function f2() {
            setInterval(function(){
                f1(function () {
                    i++;
                    i%=length;
               })
            },3000);
            setTimeout(f3,500);
            clearTimeout(f3);
        }

        function f1(a) {
            a();
            $pic.eq(i).stop().fadeIn(1000).siblings().stop().fadeOut(1000);

        }



        function f3() {
            $more.animate({
                "top": "30%",
                "opacity":"1"
            },500)
        }


    })();


    //轮播图
    ;(function () {




        //咨询师

        var $Ul = $("#main #home .corporate ul"),
            $Li = $Ul.children("li"),
            $Counsel = $("#main #home .corporate .counsel"),
            $Next = $("#main #home .corporate .next"),
            $Prv = $("#main #home .corporate .prv"),
            timer,
            index=0,
            len=$Li.length;

        auto();

        $Counsel.mouseenter(function () {
            clearInterval(timer);
        });

        $Counsel.mouseleave(function () {
            auto();
        });

        $Next.mouseenter(function () {
            clearInterval(timer);
        });

        $Next.mouseleave(function () {
            auto();
        });

        $Prv.mouseenter(function () {
            clearInterval(timer);
        });

        $Prv.mouseleave(function () {
            auto();
        });

        $Next.click(function () {
            index++;
            f();
        });

        $Prv.click(function () {
            index--;
            f();
        });

        function auto() {
            timer = setInterval(function () {
                change(function () {
                    index ++;
                    index %= (len/4);
                })
            },3000)
        }

        function f() {
            index=Math.max(0,index);
            index=Math.min(index,1);
            $Ul.css("margin-left",- $Counsel.outerWidth() * index +"px");
        }

        function change(fn) {
            fn();
            $Ul.css("margin-left",- $Counsel.outerWidth() * index +"px");
        }


        //我们的业绩轮播

        var $Result = $("#main #us .result .r-title .rt-content > div ul"),
            $RLi = $Result.children("li"),
            $TogleLi = $("#main #us .result .r-title .rt-content .toggle li"),
            $Rnext = $("#main #us .result .r-title .rt-content .r-next"),
            $Rprv = $("#main #us .result .r-title .rt-content .r-prv"),
            i=0,
            time;

        $RLi.mouseenter(function () {
            $TogleLi.eq($(this).index()).removeClass("d-n").siblings().addClass("d-n");
            clearInterval(time);
        });

        $RLi.mouseleave(function () {
            rMoveAuto();
        });

        $Rnext.mouseenter(function () {
            clearInterval(time);
        });
        $Rnext.mouseleave(function () {
            rMoveAuto();
        });
        $Rnext.click(function () {
            i++;
            i=Math.min(i,6);
            rMove();
        });

        $Rprv.mouseenter(function () {
            clearInterval(time);
        });
        $Rprv.mouseleave(function () {
            rMoveAuto();
        });
        $Rprv.click(function () {
            i--;
            i=Math.max(i,0);
            rMove();

        });

        rMoveAuto();

        function rMoveAuto(){
            time=setInterval(Imove,3000);
        }

        function Imove() {
            i++;
            i%=($(document).width()<950)?8:7;
            rMove();
        }

        function rMove(){
            $Result.css("margin-left",-i*$RLi.eq(2).width()+"px");
        }

    })();



    //首页 合作客户点击
    ;(function () {

        var $ClickLi = $("#main #home .cooperative .c-content .click ul li");

        $(function () {
            $ClickLi.eq(0).click();
        });

        $ClickLi.click(function () {
            $(this).addClass("on").siblings().removeClass("on");
            $("#main #home .cooperative .c-content > ul").eq($(this).index()).addClass("d-f").siblings("ul").removeClass("d-f");

        });

    })();

    //关于我们-咨询师展示
    ;(function () {

        var $Btn = $("#main #us .alone .btn .center ul li"),
            $Pic = $("#main #us .teacher .t-content .t-pic .t-list > ul > li"),
            $Prv = $("#main #us .teacher .btn .center .prv"),
            $Next = $("#main #us .teacher .btn .center .next"),
            len = $Btn.length,
            i=0;


        $(function () {
           $Btn.eq(i).click();
        });

        $Btn.click(function () {
            var index = $(this).index(),
                max = len -1;
            check(index,max);
            show(index);
            $Prv.click(function () {
                index --;
                if (index<0) index=0;
                show(index);
                check(index,max);
            });
            $Next.click(function () {
                index ++;
                if (index>max) index=max;
                show(index);
                check(index,max);
            });
        });

        function check(index,max){
            if (index === 0){
                $Prv.css("opacity","0");
                $Next.css("opacity","1");
            }else if( index === max){
                $Prv.css("opacity","1");
                $Next.css("opacity","0");
            }else if(0 < index < max){
                $Prv.css("opacity","1");
                $Next.css("opacity","1");
            }
        }

        function show(f) {
            $Pic.eq(f).stop().fadeIn(500).siblings().hide();
            $Btn.eq(f).addClass("on").siblings().removeClass("on");
        }


    })();

    //关于我们 我们的客户
    ;(function () {

        var $Btn = $("#main #us .customer .btn .center ul li"),
            $Pic = $("#main #us .customer .c-content .t-pic .c-list > ul"),
            $Prv = $("#main #us .customer .btn .center .prv"),
            $Next = $("#main #us .customer .btn .center .next"),
            len = $Btn.length,
            i=0;

        $(function () {
            $Btn.eq(i).click();
        });

        $Btn.click(function () {
            var index = $(this).index(),
                max = len -1;
            check(index,max);
            show(index);
            $Prv.click(
                function () {
                    index --;
                    if (index<0) index=0;
                    show(index);
                    check(index,max);
                }
            );
            $Next.click(function () {
                index ++;
                if (index>max) index=max;
                show(index);
                check(index,max);
            });
        });

        function check(index,max){

            if (index === 0){
                $Prv.css("opacity","0");
                $Next.css("opacity","1");
            }else if( index === max){
                $Prv.css("opacity","1");
                $Next.css("opacity","0");
            }else if(0 < index < max){
                $Prv.css("opacity","1");
                $Next.css("opacity","1");
            }
        }

        function show(f) {
            $Pic.eq(f).stop().fadeIn(500).siblings().hide();
            $Btn.eq(f).addClass("on").siblings().removeClass("on");
        }


    })();

    //关于我们 我们的历史
    ;(function () {

        var $Htitle = $("#main #us .history .h-content .hc-title li");

        $Htitle.click(function () {
            $(this).addClass("on").siblings().removeClass("on");
        });
    })();

    //关于我们 我们的文化
    ;(function () {

        var $cultureBtn = $("#main #us .culture .btn .center ul li");

        $cultureBtn.click(function () {
            $(this).addClass("on").siblings().removeClass("on");
        });

    })();

    //业务范围
    ;(function () {

        var $business = $("#business .b-nav li"),
            $bContent = $("#business .b-content > div");


        $business.click(function () {
            var This = $(this);
            This.find("div h3").addClass("on").end().siblings().find("div h3").removeClass("on");
            This.find("div p").addClass("on").end().siblings().find("div p").removeClass("on");
            $bContent.eq(This.index()).removeClass("d-n").siblings().addClass("d-n");

        });
    })();

    //业务流程
    ;(function () {

        var $I = $("#business .b-bottom .num > i"),
            $Num = $("#business .b-bottom .num ul li"),
            $Process = $("#business .b-bottom .process > div");

     
        Num();

        function Num() {


            if ($(window).width()<800){

                $I.css("height",parseFloat($Process.eq(4).css("top")) +$Process.eq(4).height() + "px");
                $Num.eq(1).css("top",parseFloat($Process.eq(1).css("top")) -100+"px" );
                $Num.eq(2).css("top",parseFloat($Process.eq(2).css("top")) -100+"px" );
                $Num.eq(3).css("top",parseFloat($Process.eq(3).css("top")) -100+"px" );
                $Num.eq(4).css("top",parseFloat($Process.eq(4).css("top")) -100+"px" );
                console.log($I.height());

            } else{
                $I.css("height",$Process.eq(3).height() + $Process.eq(2).height() + $Process.eq(1).height() +$Process.eq(0).height() + $Num.eq(0).height()*4  + "px");
                $Num.eq(1).css("top",$Process.eq(0).height() +80 + "px");
                $Num.eq(2).css("top",$Process.eq(1).height() +$Process.eq(0).height() +130 + "px");
                $Num.eq(3).css("top",$Process.eq(2).height() + $Process.eq(1).height() +$Process.eq(0).height() +160 + "px");
                $Num.eq(4).css("top",$Process.eq(3).height() + $Process.eq(2).height() + $Process.eq(1).height() +$Process.eq(0).height() + 200 + "px");

                $Num.eq(0).children("i").css("margin-top",($Process.eq(0).height()-20)/2 + "px");
                $Num.eq(1).children("i").css("margin-top",($Process.eq(1).height()-40)/2 + "px");
                $Num.eq(2).children("i").css("margin-top",($Process.eq(2).height()-50)/2 + "px");
                $Num.eq(3).children("i").css("margin-top",($Process.eq(3).height()-50)/2 + "px");
                $Num.eq(4).children("i").css("margin-top",($Process.eq(4).height()-20)/2 + "px");
            }

        }


    })();


    //加入我们
    ;(function () {

        var $JoinLi = $("#join .j-nav ul li"),
            $Jcontent = $("#join .j-content > div");

        $JoinLi.click(function () {
            var This = $(this);
            This.children("h5").addClass("on").end().siblings().children("h5").removeClass("on");
            This.children("p").addClass("on").end().siblings().children("p").removeClass("on");
            $Jcontent.eq(This.index()).removeClass("d-n").siblings().addClass("d-n");
        });

    })();

    //人才应聘
    ;(function () {

        var $Join = $("#join .j-content .talent ul li"),
            $joinBtn = $("#join .j-content .talent .btn .center ul li");


        $Join.click(function () {

            var This = $(this);
            This.find(".top i").addClass("on").end().siblings().find(".top i").removeClass("on");
            This.children(".bottom").stop().slideDown(500).end().siblings().children(".bottom").stop().slideUp(500);


        });


        $joinBtn.click(function () {
            $(this).addClass("on").siblings().removeClass("on");
        });

    })();

    //新闻资讯
    ;(function () {

        var $Inav = $("#information .i-nav li"),
            $newsBtn = $("#information .btn .center ul li"),
            $Icontent = $("#information .i-content > div");

        $Inav.click(function () {
            var This = $(this);
            This.find("h5").addClass("on").end().siblings().find("h5").removeClass("on");
            This.find("p").addClass("on").end().siblings().find("p").removeClass("on");
            $Icontent.eq($(this).index()).removeClass("d-n").siblings().addClass("d-n");
        });

        $newsBtn.click(function () {
            $(this).addClass("on").siblings().removeClass("on");

        });

    })();

    //资源中心
    ;(function () {

        var $Inav = $("#resources .r-nav li"),
            $resourcesBtn = $("#resources .btn .center ul li"),
            $Rcontent = $("#resources .r-content > div");

        $Inav.click(function () {
            var This = $(this);
            This.find("h5").addClass("on").end().siblings().find("h5").removeClass("on");
            This.children("p").addClass("on").end().siblings().children("p").removeClass("on");
//            $Rcontent.eq($(this).index()).removeClass("d-n").siblings().addClass("d-n");
        });

        $resourcesBtn.click(function () {
            $(this).addClass("on").siblings().removeClass("on");
        });

    })();

});









